/**
 * 防抖函数
 * @param fn
 * @param ms
 * @returns {function(...[*]=)}
 */
export const debounce = (fn, ms) => {
    let timerId;
    return function () {
        timerId && clearTimeout(timerId);
        timerId = setTimeout(() => {
            fn.apply(this, arguments);
        }, ms);
    }
};

/**
 * 节流函数
 * @param fn
 * @param ms
 * @returns {function(...[*]=)}
 */
export const throttle = (fn, ms) => {
    let timerId;
    return function () {
        if (!timerId) {
            timerId = setTimeout(() => {
                timerId = null;
                fn.apply(this, arguments);
            }, ms)
        }
    }
};
